package com.example.update.client;

import com.google.protobuf.InvalidProtocolBufferException;

import java.io.FileInputStream;
import java.io.IOException;

public class Client {
    public static void main(String[] args) throws IOException {

        // 读取文件，将读取的内容进行反序列化
        Contacts contacts = Contacts.parseFrom(
                new FileInputStream("src/main/java/com/example/update/contacts.bin"));

        // 打印
        printContacts(contacts);
    }

    private static void printContacts(Contacts contacts) throws InvalidProtocolBufferException {
        int i = 1;
        for (PeopleInfo peopleInfo : contacts.getContactsList()) {
            System.out.println("-----------联系人" + i++ + "--------------");
            System.out.println("姓名：" + peopleInfo.getName());
            System.out.println("年龄：" + peopleInfo.getAge());
            int j = 1;
            for (PeopleInfo.Phone phone : peopleInfo.getPhoneList()) {
                System.out.println("电话" + j++ + ": " + phone.getNumber());
            }
            // 未知字段
            System.out.println("未知字段：\n" + peopleInfo.getUnknownFields());
        }
    }
}
